# Unix Make

VER ?= $(shell git describe --tags)
GITHASH = $(shell git rev-parse HEAD)
BUILDDATE = $(shell date '+%Y/%m/%d %H:%M:%S')

SRCS = *.go
EXEC = jetserver

GO = go
CGO_ENABLED ?= 0
GO_OUTPUT := build/${EXEC}

GOX = gox
GOX_ARCH = 386 amd64
GOX_OS = windows linux
GOX_OSARCH = darwin/amd64 linux/arm
GOX_OUTPUT = gox_build/${EXEC}_{{.OS}}_{{.Arch}}

LDFLAGS = -s -w -X 'main.Version=${VER}' -X 'main.Builddate=${BUILDDATE}' -X main.Buildhash=${GITHASH}

# Targets

go: clean build

install:
	cp ${GO_OUTPUT} ${GOPATH}/bin/

build:
	CGO_ENABLED=${CGO_ENABLED} ${GO} build -o "${GO_OUTPUT}" -ldflags "${LDFLAGS}"

clean:
	rm -rf build/

test: go
	${GO} test -race -v

gox: gox_clean gox_build

gox_build:
	CGO_ENABLED=${CGO_ENABLED} ${GOX} -arch="${GOX_ARCH}" \
	-ldflags="${LDFLAGS}" \
	-os="${GOX_OS}" \
	-osarch="${GOX_OSARCH}" \
	-output="${GOX_OUTPUT}" \
	-verbose .
	cd gox_build/ && tar -zcvf binaries_${EXEC}_${VER}.tgz *

gox_clean:
	rm -rf gox_build/

.PHONY: build clean gox_build gox_clean